package com.myBlog.controller;

import com.myBlog.domain.ResponseResult;
import com.myBlog.domain.dto.UserDTO;
import com.myBlog.domain.vo.PageVo;
import com.myBlog.service.BlogLoginService;
import com.myBlog.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;


    /**
     * 条件分页查询用户
     * @param pageNum
     * @param pageSize
     * @param userDTO
     * @return
     */
    @GetMapping("/getInfo/list")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, UserDTO userDTO) {
        return userService.list(pageNum, pageSize, userDTO);
    }

    /**
     * 根据id查询用户信息
     * @param userId
     * @return
     */
    @GetMapping("{id}")
    public ResponseResult getUserInfo(@PathVariable("id") Long userId) {
        return userService.getUserInfo(userId);
    }


    /**
     * 添加用户
     * @param userDTO
     * @return
     */
    @PostMapping
    public ResponseResult addUser(@RequestBody UserDTO userDTO) {
        return userService.addUser(userDTO);
    }

    /**
     * 根据ids删除用户
     * @param ids
     * @return
     */
    @DeleteMapping("{id}")
    public ResponseResult deleteById(@PathVariable("id") List<Long> ids) {
        return userService.deleteById(ids);
    }

    /**
     * 修改用户
     * @param userDTO
     * @return
     */
    @PutMapping
    public ResponseResult updateUser(@RequestBody UserDTO userDTO) {
        return userService.updateUser(userDTO);
    }
}
